package date_demo;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoField;
/**
 * @author ChenYongHao
 * @date 2023/5/4 10:02
 * @desc 描述：本地日期，可以获取年、月、日、星期几
 */
public class LocalDate_Demo {
    public static void main(String[] args) {
        // 静态方法，获取当前年月日
        LocalDate localDate = LocalDate.now();

        // 静态方法，构造指定年月日
        LocalDate localDate1 = LocalDate.of(2019, 9, 12);

        // 获取年、月、日、星期几
        int year = localDate.getYear();
        Month month = localDate.getMonth();
        int day = localDate.getDayOfMonth();
        DayOfWeek dayOfWeek = localDate.getDayOfWeek();
        System.out.println("年--"+year);
        System.out.println("月--"+month);
        System.out.println("天--"+day);
        System.out.println("星期--"+dayOfWeek);
        System.out.println("---------->>");

        // 获取年、月、日、星期几
        int year1 = localDate.get(ChronoField.YEAR);
        int month1 = localDate.get(ChronoField.MONTH_OF_YEAR);
        int day1 = localDate.get(ChronoField.DAY_OF_MONTH);
        int dayOfWeek1 = localDate.get(ChronoField.DAY_OF_WEEK);
        System.err.println("年--"+year1);
        System.err.println("月--"+month1);
        System.err.println("天--"+day1);
        System.err.println("星期--"+dayOfWeek1);
    }
}
